package com.ftg.learn.controller;

import com.ftg.learn.dao.Peijian;
import com.ftg.learn.service.PeijianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@CrossOrigin
@RequestMapping("/pei")
public class PeijianController {

    @Autowired
    PeijianService peijianService;

    @GetMapping("/select")
    public Map<String,Object> select(int page , int limit, String name){
        Map<String ,Object>  map=new HashMap<>();
        List<Peijian> list=peijianService.select(page,limit,name);
        map.put("data",list);
        map.put("name",name);
        map.put("code","0");
        map.put("count",peijianService.getCount(name));
        return map;
    }

    @GetMapping("/picture")
    public Map<String,Object> selectpicture(){
        Map<String ,Object>  map=new HashMap<>();
        List<Peijian> list=peijianService.selectpicture();
        map.put("data",list);
        map.put("code","0");
        return map;
    }

    //添加
    @PostMapping("/add")
    public int add(Peijian peijian){
        peijian.setId(UUID.randomUUID().toString());
        System.out.println(peijian.getName());
        return peijianService.add(peijian);
    }
    //删除
    @DeleteMapping("/delete/{id}")
    public int delete(@PathVariable  String id){

        return  peijianService.delete(id);
    }
    //修改
    @PostMapping("/update")
    public int update(Peijian peijian){
        return  peijianService.update(peijian);
    }
}
